package com.nutshare.lt;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Properties;

public class LT
{

    private ArrayList<LTWorkspace> lt = new ArrayList<LTWorkspace>();

    public LT()
    {
    }

    private void init(String arg)
    {
        FileInputStream fi = null;

        try
        {
            fi = new FileInputStream(arg);
        } catch (FileNotFoundException e)
        {
            System.out.println(e.getMessage());
            System.exit(1);
        }

        Properties prop = new Properties();
        try
        {
            prop.load(fi);
        }
        catch(IOException e)
        {
            System.out.println(e.getMessage());
            System.exit(1);
        }

        for(int i=0; i<100; i++)
        {
            String name = prop.getProperty("Name" + i);
            if(name == null)
            {
                continue;
            }
            String max = prop.getProperty("Max" + i);
            Integer maxParsed;
            try
            {
                maxParsed = Integer.parseInt(max.trim());
            }
            catch (NumberFormatException e)
            {
                System.out.println("Max for i" + ": " + e.getMessage());
                continue;
            }
            String count = prop.getProperty("Count" + i);
            Integer countParsed;
            try
            {
                countParsed = Integer.parseInt(count.trim());
            }
            catch (NumberFormatException e)
            {
                System.out.println("Count for i" + ": " + e.getMessage());
                continue;
            }
            String file = prop.getProperty("File"+i);
            LTWorkspace ltw = new LTWorkspace(name, maxParsed, file, countParsed);
            this.lt.add(ltw);

            ltw.showWorkspace();


        }
    }

    public static void main(String[] args)
    {
        if (args.length < 1)
        {
            throw new RuntimeException("Configuration file not specified");
        }

        LT lt = new LT();
        lt.init(args[0]);

    }

}
